package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsUserReceGroupMessage;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface BmsUserReceGroupMessageDao extends BaseJPADao<BmsUserReceGroupMessage,Integer> {
    List<BmsUserReceGroupMessage> findByGroupMessageId(Integer groupMessageId, Pageable pageable);

    List<BmsUserReceGroupMessage> findByGroupMessageId(Integer groupMessageId);

    @Query(value="select count(id) num ,group_message_id groupMessageId from bms_user_rece_group_message where " +
            "group_message_id in (?1) group by group_message_id",nativeQuery=true)
    List<Map<String,Object>> countGroupMessageSendUserNum(Set groupMessageId);

    @Query(value="update bms_user_rece_group_message set is_read = 1 where id in (?1)",nativeQuery=true)
    @Modifying
    Integer selfUpdateUserMessageToRead(Set ids);

    List<BmsUserReceGroupMessage> findByIdIn(Set ids);

    @Query(value="select burgm.bms_user_id,bu.login_name,bu.head_img,burgm.new_time from bms_user_rece_group_message burgm " +
            "left join bms_user bu on burgm.bms_user_id = bu.id " +
            "where burgm.group_message_id = ?1 and burgm.bms_user_id in (?2) order by burgm.new_time desc",nativeQuery=true)
    List<Map<String,Object>> sendGroupMessageRece(Integer groupMessageId,Set<Integer> userId);

}
